#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<int> findAnagrams(string s, string p)
    {
        vector<int> ret;
        int hash1[26] = { 0 };
        for (auto ch : p) hash1[ch - 'a']++;

        int hash2[26] = { 0 };
        int m = p.length();

        int count = 0;
        for (int left = 0, right = 0; right < s.length(); right++)
        {
            char in = s[right];
            if (++hash2[in - 'a'] <= hash1[in - 'a']) count++;

            if (right - left + 1 > m)
            {
                char out = s[left++];
                if (hash2[out - 'a']-- <= hash1[out - 'a']) count--;

            }
            if (m == count) ret.push_back(left);
        }
        return ret;
    }
};